﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ec_System.Facade.Web;

namespace Ec_System.WebUI.Areas.Web.Controllers
{
    public class CommonController : Controller
    {
        // GET: Web/Common
        AreasFacade areasFacade = new AreasFacade();

        /// <summary>
        /// 获取行政区--省
        /// </summary>
        /// <returns></returns>
        public ActionResult GetProvice()
        {
            var model = areasFacade.GetAllAreas();
            return Json(model.ProviceList, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取行政区--市
        /// </summary>
        /// <param name="id">省的ID</param>
        /// <returns></returns>
        public ActionResult GetCity(string id)
        {
            var model = areasFacade.GetAllAreas();
            return Json(model.CityList.Where(m => m.ParentID == id), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取行政区--区县
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult GetTown(string id)
        {
            var model = areasFacade.GetAllAreas();
            return Json(model.TownList.Where(m => m.ParentID == id), JsonRequestBehavior.AllowGet);
        }
    }
}